import axios from 'axios'
import METHOD from './mothed'

const api = axios.create({
    baseURL: 'https://cnodejs.org',
    timeout: 5000
})
export function request(method, url, params) {
    switch (method) {
        case METHOD.GET:
            return get(url, params)
        case METHOD.POST:
            return post(url, params)
    }
}

function get(url, params) {
    return api.get(url, params)
}

function post(url, params) {
    return api.post(url, params)
}

api.interceptors.request.use(function (config) {
    return config
}, function (error) {
    return Promise.reject(error)
})

api.interceptors.response.use(function (response) {
    return response
}, function (error) {
    return Promise.reject(error)
})

